#include <cmath>
#include <iostream>
#include <unordered_map>

bool ie(int n) {
  if (n <= 1) {
    return false;
  }
  for (int i = 2; i <= static_cast<int>(std::sqrt(n)) + 1; i++) {
    if (n % i == 0) {
      return false;
    }
  }
  return true;
}

int ce(int nu) {
  int le = nu - 1;
  int he = nu + 1;
  while (true) {
    if (ie(le)) {
      return le;
    }
    if (ie(he)) {
      return he;
    }
    le--;
    he++;
  }
}

int cer(const std::string& w) {
  std::unordered_map<std::string, int> dp = {
      {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
      {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}};
  if (w.length() != 3) {
    return -1;
  }
  int n = 100 * dp[std::string(1, w[0])] + 10 * dp[std::string(1, w[1])] + dp[std::string(1, w[2])];
  return n;
}

int main() {
  std::string input;
  std::getline(std::cin, input);
  std::string word;
  std::istringstream iss(input);
  iss >> word;
  int n = cer(word);

  if (n == -1 || n < 100 || n > 999) {
    std::cout << "Wrong input" << std::endl;
  } else {
    std::cout << ce(n) << std::endl;
  }

  return 0;
}

